package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.constant.*;
import org.jsola.hr.dto.EmpInfoAddDTO;
import org.jsola.hr.dto.EmpInfoUpdateDTO;
import org.jsola.hr.entity.EmpInfoDO;
import org.jsola.hr.query.EmpInfoQuery;
import org.jsola.hr.service.IEmpInfoService;
import org.jsola.hr.vo.EmpInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 员工信息
 *
 * @author zhr
 */
@Component
public class EmpInfoTestHelper extends BaseTestHelper {
    
    @Autowired
    private IEmpInfoService empInfoService;

    /**
     * 生成add测试数据
     * @return EmpInfoAddDTO
     */
    public EmpInfoAddDTO getEmpInfoAddDTO(){
        EmpInfoAddDTO empInfoAddDTO = new EmpInfoAddDTO();
        empInfoAddDTO.setEmpSocStatus(EmpSocStatus.NOT_SOC.getValue());
        empInfoAddDTO.setPlanIncreaseDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empInfoAddDTO.setPlanStopSocDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empInfoAddDTO.setSocDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empInfoAddDTO.setStopSocDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empInfoAddDTO.setSocProgId(getRandomValue("varchar",32));
        empInfoAddDTO.setSealedDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empInfoAddDTO.setCompanyBeginPayDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empInfoAddDTO.setIncreaseDate(getRandomValue("datetime",0));
        empInfoAddDTO.setCertificateType(CertificateTypeEnum.ID_CARD.getValue());
        empInfoAddDTO.setNationality(getRandomValue("varchar",11));
        empInfoAddDTO.setEmploymentType(EmploymentTypeEnum.雇员.getValue());
        empInfoAddDTO.setEmpAge(SafeKit.getInteger(getRandomValue("int",5)));
        empInfoAddDTO.setRetirementAge(SafeKit.getInteger(getRandomValue("int",3)));
        empInfoAddDTO.setUserId(getRandomValue("varchar",32));
        empInfoAddDTO.setUnionId(getRandomValue("varchar",32));
        empInfoAddDTO.setPreJoinDep(getRandomValue("varchar",255));
        empInfoAddDTO.setPreJoinPosition(getRandomValue("varchar",255));
        empInfoAddDTO.setNumber(getRandomValue("varchar",32));
        empInfoAddDTO.setName(getRandomValue("varchar",50));
        empInfoAddDTO.setNamePinyin(getRandomValue("varchar",128));
        empInfoAddDTO.setIdCard(getRandomValue("varchar",20));
        empInfoAddDTO.setNation(getRandomValue("varchar",50));
        empInfoAddDTO.setBirthday(getRandomValue("varchar",50));
        empInfoAddDTO.setGender(GenderEnum.MAN.getValue());
        empInfoAddDTO.setContractSubject(getRandomValue("varchar",32));
        empInfoAddDTO.setPhone(getRandomValue("varchar",11));
        empInfoAddDTO.setEmail(getRandomValue("varchar",64));
        empInfoAddDTO.setEmpPhoto(getRandomValue("varchar",255));
        empInfoAddDTO.setHighestEducation(getRandomValue("varchar",50));
        empInfoAddDTO.setMaritalStatus(EmpMaritalStatus.MARRIED.getValue());
        empInfoAddDTO.setBirthStatus(EmpBirthStatus.HAS_BRED.getValue());
        empInfoAddDTO.setChannelId(getRandomValue("varchar",32));
        empInfoAddDTO.setPoliticalStatus(EmpPoliticalStatus.PARTY_MEMBER.getValue());
        empInfoAddDTO.setPartyDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empInfoAddDTO.setPartySite(getRandomValue("varchar",50));
        empInfoAddDTO.setBirthplace(getRandomValue("varchar",100));
        empInfoAddDTO.setNativeLocation(getRandomValue("varchar",100));
        empInfoAddDTO.setRegType(RegTypeEnum.URBAN.getValue());
        empInfoAddDTO.setCurrentAddrId(getRandomValue("varchar",32));
        empInfoAddDTO.setCurrentLocation(getRandomValue("varchar",100));
        empInfoAddDTO.setCompanyId(getRandomValue("varchar",32));
        empInfoAddDTO.setBankCard(getRandomValue("varchar",50));
        empInfoAddDTO.setBankName(getRandomValue("varchar",100));
        empInfoAddDTO.setBankCardBranch(getRandomValue("varchar",255));
        empInfoAddDTO.setBankPlaceId(getRandomValue("varchar",32));
        empInfoAddDTO.setBankPlace(getRandomValue("varchar",100));
        empInfoAddDTO.setSocType(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        empInfoAddDTO.setIsFirstSoc(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        empInfoAddDTO.setSocCard(getRandomValue("varchar",60));
        empInfoAddDTO.setIsFirstPf(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        empInfoAddDTO.setPfCard(getRandomValue("varchar",50));
        empInfoAddDTO.setHealthCondition(getRandomValue("varchar",100));
        empInfoAddDTO.setHasWeightyMedicalHis(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        empInfoAddDTO.setJobTitle(getRandomValue("varchar",50));
        empInfoAddDTO.setJoinWorkDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empInfoAddDTO.setWorkingUnitName(getRandomValue("varchar",100));
        empInfoAddDTO.setPutonghuaLevel(getRandomValue("varchar",20));
        empInfoAddDTO.setSpeciality(getRandomValue("varchar",255));
        empInfoAddDTO.setPrizeWinning(getRandomValue("varchar",255));
        empInfoAddDTO.setEnglishLevel(getRandomValue("varchar",20));
        empInfoAddDTO.setNcreLevel(getRandomValue("varchar",20));
        empInfoAddDTO.setTargetPost(getRandomValue("varchar",100));
        empInfoAddDTO.setAnnexIdCard(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexHousehold(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexDiploma(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexDegree(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexPractising(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexMajor(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexReward(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexNoCriminal(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexBlackWhitePhoto(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexPthLevel(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexEnglishLevel(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexNcreLevel(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexDrivingLicense(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexPersonPhoto(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexSalaryCard(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexSocCard(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexPfCard(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexLaborContract(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexOnbResume(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexOnbCheckup(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexLastLeaveCert(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexWorkApply(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexAdjustNotice(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexPersonalChange(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexSocTransfer(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexPerformanceReport(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexOtherInfos(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexLeaveAppro(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexLeaveCert(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexLeaveApply(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexHandoverTable(getRandomValue("text",2147483647));
        empInfoAddDTO.setSupervisor(getRandomValue("varchar",50));
        empInfoAddDTO.setEmployType(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        empInfoAddDTO.setInformalType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        empInfoAddDTO.setFormalType(FormalTypeEnum.PROBATION.getValue());
        empInfoAddDTO.setIsImprove(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        empInfoAddDTO.setPostType(PostType.LABOUR.getValue());
        empInfoAddDTO.setContractsStatus(ContractsStatus.NOT_INITIATED.getValue());
        empInfoAddDTO.setManagerForm(SafeKit.getInteger(getRandomValue("tinyint",4)));
        empInfoAddDTO.setWorkCityId(getRandomValue("varchar",32));
        empInfoAddDTO.setIssuedBy(getRandomValue("varchar",100));
        empInfoAddDTO.setCardStartDate(getRandomValue("varchar",100));
        empInfoAddDTO.setCardEndDate(getRandomValue("varchar",100));
        empInfoAddDTO.setWorkCity(getRandomValue("varchar",100));
        empInfoAddDTO.setJoinFormStatus(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        empInfoAddDTO.setPreJoinDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empInfoAddDTO.setJoinDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empInfoAddDTO.setProbation(ProbationEnum.PRO_0.getValue());
        empInfoAddDTO.setProbationDays(SafeKit.getInteger(getRandomValue("int",11)));
        empInfoAddDTO.setTurnStraightDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empInfoAddDTO.setLeaveDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empInfoAddDTO.setLeaveReason(getRandomValue("varchar",255));
        empInfoAddDTO.setChangeStatus(SafeKit.getInteger(getRandomValue("tinyint",4)));
        empInfoAddDTO.setVerified(false);
        empInfoAddDTO.setStatus(EmpInfoStatus.WAIT_ENTRY.getValue());
        empInfoAddDTO.setApprovalStatus(SafeKit.getInteger(getRandomValue("tinyint",4)));
        empInfoAddDTO.setArrival(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        empInfoAddDTO.setJoinCityCode(getRandomValue("varchar",50));
        empInfoAddDTO.setArchivesNumber(getRandomValue("varchar",80));
        empInfoAddDTO.setJoinCityName(getRandomValue("varchar",100));
        empInfoAddDTO.setArchivesRemake(getRandomValue("text",2147483647));
        empInfoAddDTO.setRecruitChannels(getRandomValue("varchar",255));
        empInfoAddDTO.setRetirementStatus(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        empInfoAddDTO.setRetirementDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empInfoAddDTO.setRetirementRemark(getRandomValue("varchar",255));
        empInfoAddDTO.setBloodGroup(BloodGroupEnum.A.getValue());
        empInfoAddDTO.setAnnexNoPregnant(getRandomValue("text",2147483647));
        empInfoAddDTO.setAnnexLeaving(getRandomValue("text",2147483647));
        empInfoAddDTO.setSalaryType(SalaryFileTypeEnum.NO_SALARY.getValue());
        empInfoAddDTO.setAlipayAccount(getRandomValue("varchar",50));
        empInfoAddDTO.setSalaryRuleId(getRandomValue("varchar",32));
        empInfoAddDTO.setServiceFeeRuleId(getRandomValue("varchar",32));
        empInfoAddDTO.setRemark(getRandomValue("varchar",200));
        empInfoAddDTO.setTag(getRandomValue("text",500));
        return empInfoAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpInfoUpdateDTO
     */
    public EmpInfoUpdateDTO getEmpInfoUpdateDTO(EmpInfoVO empInfoVO){
        return empInfoService.selectDOById(empInfoVO.getId(), SITE_ID).to(EmpInfoUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpInfoQuery
     */
    public EmpInfoQuery getEmpInfoQuery() {
        EmpInfoQuery empInfoQuery = new EmpInfoQuery();
        List<EmpInfoDO> empInfoDOList = empInfoService.list(new EmpInfoDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empInfoDOList)) {
            EmpInfoDO empInfoDO = empInfoDOList.get(0);
            empInfoQuery = empInfoDO.to(EmpInfoQuery.class);
            if (empInfoDO.getBirthday() != null) {
                empInfoQuery.setBirthdayStart(empInfoDO.getBirthday());
                empInfoQuery.setBirthdayEnd(empInfoDO.getBirthday() );
            }
            if (empInfoDO.getPartyDate() != null) {
                empInfoQuery.setPartyDateStart(DateKit.getBeforeDay(empInfoDO.getPartyDate(),-1));
                empInfoQuery.setPartyDateEnd(DateKit.getBeforeDay(empInfoDO.getPartyDate(),1));
            }
            if (empInfoDO.getJoinWorkDate() != null) {
                empInfoQuery.setJoinWorkDateStart(DateKit.getBeforeDay(empInfoDO.getJoinWorkDate(),-1));
                empInfoQuery.setJoinWorkDateEnd(DateKit.getBeforeDay(empInfoDO.getJoinWorkDate(),1));
            }
            if (empInfoDO.getPreJoinDate() != null) {
                empInfoQuery.setPreJoinDateStart(DateKit.getBeforeDay(empInfoDO.getPreJoinDate(),-1));
                empInfoQuery.setPreJoinDateEnd(DateKit.getBeforeDay(empInfoDO.getPreJoinDate(),1));
            }
            if (empInfoDO.getJoinDate() != null) {
                empInfoQuery.setJoinDateStart(DateKit.getBeforeDay(empInfoDO.getJoinDate(),-1));
                empInfoQuery.setJoinDateEnd(DateKit.getBeforeDay(empInfoDO.getJoinDate(),1));
            }
            if (empInfoDO.getTurnStraightDate() != null) {
                empInfoQuery.setTurnStraightDateStart(DateKit.getBeforeDay(empInfoDO.getTurnStraightDate(),-1));
                empInfoQuery.setTurnStraightDateEnd(DateKit.getBeforeDay(empInfoDO.getTurnStraightDate(),1));
            }
            if (empInfoDO.getLeaveDate() != null) {
                empInfoQuery.setLeaveDateStart(DateKit.getBeforeDay(empInfoDO.getLeaveDate(),-1));
                empInfoQuery.setLeaveDateEnd(DateKit.getBeforeDay(empInfoDO.getLeaveDate(),1));
            }
            if (empInfoDO.getGmtCreate() != null) {
                empInfoQuery.setGmtCreateStart(DateKit.getBeforeDay(empInfoDO.getGmtCreate(),-1));
                empInfoQuery.setGmtCreateEnd(DateKit.getBeforeDay(empInfoDO.getGmtCreate(),1));
            }
            if (empInfoDO.getGmtModified() != null) {
                empInfoQuery.setGmtModifiedStart(DateKit.getBeforeDay(empInfoDO.getGmtModified(),-1));
                empInfoQuery.setGmtModifiedEnd(DateKit.getBeforeDay(empInfoDO.getGmtModified(),1));
            }
        }
        return empInfoQuery;
    }

    /**
     * 保存示例
     * @return EmpInfoVO
     */
    public EmpInfoVO saveEmpInfoExample(){
        EmpInfoAddDTO addDTO = this.getEmpInfoAddDTO();
        EmpInfoVO empInfoVO = empInfoService.save(addDTO,buildTokenUser());
        return empInfoVO;
    }

    public EmpInfoVO saveEmpInfoExample(String companyId, int employType, int contractsStatu, int empStatu, int informalType, int formalType) {
        EmpInfoAddDTO addDTO = this.getEmpInfoAddDTO();
        addDTO.setCompanyId(companyId);
        addDTO.setEmployType(employType == 1);
        addDTO.setContractsStatus(contractsStatu);
        addDTO.setStatus(empStatu);
        addDTO.setInformalType(informalType);
        addDTO.setFormalType(formalType);
        return empInfoService.save(addDTO, buildTokenUser());
    }

    public EmpInfoVO saveEmpInfoExample(String companyId) {
        EmpInfoAddDTO addDTO = this.getEmpInfoAddDTO();
        addDTO.setCompanyId(companyId);
        return empInfoService.save(addDTO, buildTokenUser());
    }


}

